package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.service.TmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Author: Shi san
 * @Date: 2025/7/9 09:07
 * @Description:
 **/
@RestController
public class TmsController {
    @Autowired
    TmsService tmsService;

    @RequestMapping("/sumtotal")
    public Object sumtotal(String newdate){
        List<Map> list = tmsService.sumtotal(newdate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        jsonObject.put("data",list.get(0).get("SUM(amount)"));
        return jsonObject;
    }

    @RequestMapping("/bingtotal")
    public Object bingtotal(){
        List<Map> list = tmsService.bingtotal();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");

        JSONArray jsonArray = new JSONArray();
        for (Map map : list) {
            JSONObject dataObject = new JSONObject();
            dataObject.put("name",map.get("type"));
            dataObject.put("value",map.get("sum"));
            jsonArray.add(dataObject);
        }
        jsonObject.put("data",jsonArray);
        return jsonObject;
    }

    @RequestMapping("/basetotal")
    public Object basetotal(){
        List<Map> list = tmsService.basetotal();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");

        JSONObject dataObject = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        for (Map map : list) {
            JSONObject data = new JSONObject();
            data.put("name",map.get("name"));
            data.put("value",map.get("count"));
            jsonArray.add(data);
            dataObject.put("mapData",jsonArray);
        }
        jsonObject.put("data",dataObject);
        return jsonObject;
    }
}
